package com.portal.signature.utils;

import cn.hutool.crypto.SecureUtil;
import cn.hutool.crypto.asymmetric.Sign;
import cn.hutool.crypto.asymmetric.SignAlgorithm;
import lombok.extern.slf4j.Slf4j;

/**
 * hutool加签验签工具类
 *
 * @author Amadeus
 * @date 2022/07/04
 */
@Slf4j
public class HutoolSecureUtil {

    public static final Sign SIGN = SecureUtil.sign(SignAlgorithm.MD5withRSA);

    public static byte[] signSecure(byte[] content) {
        return SIGN.sign(content);
    }

    public static boolean verify(byte[] content, byte[] signed) {
        return SIGN.verify(content, signed);
    }

    public static void main(String[] args) {
        //实用度有待测试
        //不是同一个SIGN验签失败 不理解怎么不同服务使用
        byte[] content = "我是一段测试字符串".getBytes();
        byte[] bytes = signSecure(content);
        boolean verify = verify(content, bytes);
        log.info("加密结果:{}", verify);
    }

}
